package com.fs.spring.example01;

import com.fs.spring.example01.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author shuai.fang
 * @date：2017-08-02
 * @description：
 */
public class MyBeanPostProcessor implements BeanPostProcessor {

	private static Logger logger = LoggerFactory.getLogger(MyBeanPostProcessor.class);

	public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
		if (beanName.equals("person")) {
			Person person = (Person) bean;
			logger.info("postProcessBeforeInitialization person.name -> {}", person.getName());
			person.setName("adsfadfasdf");
		}
		return bean;
	}

	public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
		if (beanName.equals("person")) {
			Person person = (Person) bean;
			logger.info("postProcessAfterInitialization person.name -> {}", person.getName());
			person.setName("35234523452345");
		}
		return bean;
	}
}
